const {ccclass, property} = cc._decorator;
import JoyStick from "./JoyStick";
import AppDelegate from "./AppDelegate";
import { dispatchEvent } from "./Managers/EventManager";
import { EVT_CREATE_PLAYER } from "./Core/AppEvent";
import { PLAYER_TYPE, WEAPON_TYPE, GAME_STATE, SCENE_TYPE } from "./Core/AppDef";
import WindowUtils from "./Tools/WindowUtils";


@ccclass
export default class RoomLayer extends cc.Component {
    @property(cc.Label)
    labelTitle: cc.Label = null;
    @property(cc.Node)
    labelRoom: cc.Node = null;
    @property(cc.Node)
    menu1:cc.Node = null;
    @property(cc.Node)
    menu2:cc.Node = null;
    @property(cc.Node)
    userNameLayout:cc.Node = null;
    @property(cc.Node)
    roomNameLayout:cc.Node = null;

    onLoad () {
        this.menu1.active = true;
        this.menu2.active = false;
        this.labelTitle.string = "游 戏 大 厅";
        this.onUpdate();
    }

    onUpdate () {
        this.userNameLayout.removeAllChildren();
        if(AppDelegate.userModel.getMyName() != ""){
            this.onCreateLabel(AppDelegate.userModel.getMyName(), this.userNameLayout);
        }
    }


    onClickCreateRoom(event) {
        this.roomNameLayout.removeAllChildren();
        // this.onCreateLabel("房间1", this.roomNameLayout);
        this.labelTitle.string = "房  间";
        AppDelegate.gameModel.setGameState(GAME_STATE.Room);
        this.menu1.active = false;
        this.menu2.active = true;
        this.labelRoom.active = false;
    }

    onQuitRoom(event) {
        this.roomNameLayout.removeAllChildren();
        this.labelTitle.string = "游 戏 大 厅";
        AppDelegate.gameModel.setGameState(GAME_STATE.Hall);
        this.menu1.active = true;
        this.menu2.active = false;
        this.labelRoom.active = true;
    }

    onClickStartGame(event) {
        AppDelegate.gameModel.setGameState(GAME_STATE.Game);
        cc.director.loadScene(SCENE_TYPE.GAME);
    }

    onCreateLabel(str, parent) {
        var node = new cc.Node('text'); 
        node.addComponent(cc.Label);
        node.getComponent(cc.Label).fontSize = 40;
        node.getComponent(cc.Label).string = str;
        node.color = cc.color(0x00, 0x00, 0x00);
        parent.addChild(node)
    }
}
